package com.bestcem.xm.user.mq.receiver.biz.rabbit;

import com.bestcem.xm.user.mq.message.organization.OrgCreateMessage;
import com.bestcem.xm.user.mq.receiver.biz.ReceiverService;
import com.bestcem.xm.user.mq.receiver.biz.UserConsumers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
@ConditionalOnProperty(prefix = "application", name = "mqType", havingValue = "rabbit")
public class RabbitConsumers implements UserConsumers {

    private final ReceiverService receiverService;

    public RabbitConsumers(ReceiverService receiverService) {
        this.receiverService = receiverService;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<OrgCreateMessage>> orgCreated() {
        return receiverService::orgCreated;
    }
}
